import request from '@/utils/request';
import { getPageSize } from '@/utils/common';

// 一、行车档案
// 1、查询行车档案列表
export async function selectArchivesList(params) {
    params.pageSize = params.pageSize || getPageSize();
    return request(`/server/api/tms/tms-archives/selectList`, {
        method: 'POST',
        body: params,
    });
}

// 2、查询行车档案详情
export async function selectArchivesDetail(params) {
    const { isHK, ...body } = params;
    const url = isHK ? 'selectHKDetails' : 'selectDetails';
    return request(`/server/api/tms/tms-archives/${url}`, {
        method: 'POST',
        body: body,
    });
}
//3、新增、编辑--行车档案
export async function archivesOperate(params) {
    const { operateType, isHK, ...body } = params;
    let url = isHK ? 'changeHKArchives' : params.id ? 'updateArchives' : 'insertArchives';
    return request(`/server/api/tms/tms-archives/${url}`, {
        method: 'POST',
        body,
    });
}
//3、1 新增、编辑--二车队行车档案 POST /tms-archives/updateOneTeamArchives POST /tms-archives/insertOneTeamArchives
export async function archivesOneTeamOperate(params) {
    const { operateType, isHK, ...body } = params;
    let url = params.id ? 'updateOneTeamArchives' : 'insertOneTeamArchives';
    return request(`/server/api/tms/tms-archives/${url}`, {
        method: 'POST',
        body,
    });
}
// 4、行车档案 删除
export async function removeArchives(params) {
    return request(`/server/api/tms/tms-archives/deleteArchives`, {
        method: 'POST',
        body: params,
    });
}

// 5、行车档案 确认
export async function confirmArchives(params) {
    return request(`/server/api/tms/tms-archives/confirmArchives`, {
        method: 'POST',
        body: params,
    });
}
// 6、行车档案 提交
export async function commitArchives(params) {
    return request(`/server/api/tms/tms-archives/commitArchives`, {
        method: 'POST',
        body: params,
    });
}
// 7、行车档案 试算
export async function trialFeeArchives(params) {
    const { type, ...body } = params;
    return request(`/server/api/tms/tms-archives/trialArchives`, {
        method: 'POST',
        body,
    });
}

/**
 * 查询附件
 */
export async function selectFileList(params) {
    return request(`/server/api/tms/attachment/selectFileList`, {
        method: 'POST',
        body: params,
    });
}

//二、行车档案--车次
// 1、车次--列表
export async function trainInfoList(params) {
    return request(`/server/api/tms/tms-archives-trains/selectTrainsList`, {
        method: 'POST',
        body: params,
    });
}
//2、行车档案--车次 详情
export async function trainInfoDetails(params) {
    return request(`/server/api/tms/tms-archives-trains/selectDetails`, {
        method: 'POST',
        body: params,
    });
}

//3、行车档案--车次 + 杂费 新增、编辑
export async function trainInfoOperate(params) {
    const url = params.id ? 'updateArchivesTrains' : 'insertArchivesTrains';
    return request(
        `/server/api/tms/tms-archives-trains/${url}`,
        {
            method: 'POST',
            body: params,
        },
        true
    );
}
//3.1 行车档案--一车次 + 杂费 新增、编辑 POST /tms-archives-trains/updateOneTeamArchivesTrains
export async function trainInfoOneTeamOperate(params) {
    const url = params.id ? 'updateOneTeamArchivesTrains' : 'insertOneTeamArchivesTrains';
    return request(
        `/server/api/tms/tms-archives-trains/${url}`,
        {
            method: 'POST',
            body: params,
        },
        true
    );
}
//4、删除车次：
export async function deleteTrains(params) {
    return request(`/server/api/tms/tms-archives-trains/deleteTrains`, {
        method: 'POST',
        body: params,
    });
}
//5、中港车作废
export async function cancelArchives(params) {
    return request(`/server/api/tms/tms-archives/cancelArchives`, {
        method: 'POST',
        body: params,
    });
}
// 6、中港车重新拉取
export async function pullArchivesByP2(params) {
    return request(`/server/api/tms/tms-archives/pullArchivesByP2`, {
        method: 'POST',
        body: params,
    });
}
//7、放空档案--中港车---新增、编辑
export async function emptyArchivesOperate(params) {
    const url = params.id ? 'updateEmptyArchives' : 'addEmptyArchives';
    return request(
        `/server/api/tms/tms-archives/${url}`,
        {
            method: 'POST',
            body: params,
        },
        true
    );
}
//8、放空档案--中港车---详情
export async function selectEmptyDetails(params) {
    return request(`/server/api/tms/tms-archives/selectEmptyDetails`, {
        method: 'POST',
        body: params,
    });
}
//转为本地
export async function toLocal(params) {
    return request(`/server/api/tms/tms-archives/toLocal`, {
        method: 'POST',
        body: params,
    });
}

//二（一）、行车档案--车次--杂费：
// 1、行车档案 -- 杂费列表
export async function incidentalInfoList(params) {
    const { type, ...body } = params;
    return request(`/server/api/tms/tms-archives-trains/selectMiscellaneousList`, {
        method: 'POST',
        body,
    });
}
//中港车拉取杂费
export async function pullIncidentals(params) {
    const { type, ...body } = params;
    return request(`/server/api/tms/tms-miscellaneous/pullIncidentals`, {
        method: 'POST',
        body,
    });
}

//三、加油：
// 1、行车档案 -- 加油列表
export async function oilInfoList(params) {
    const { type, ...body } = params;
    return request(`/server/api/tms/tms-archives-oil/selectListByArchives`, {
        method: 'POST',
        body,
    });
}
// 2、行车档案 --加油详情(原来的接口) /tms/tms-oil/selectDetails
export async function oilInfoDetails(params) {
    return request(`/server/api/tms/tms-archives-oil/selectDetails`, {
        method: 'POST',
        body: params,
    });
}
//3、行车档案 新增、编辑加油记录 (编辑用原来的加油接口)  tms-oil/updateOil
export async function oilInfoOperate(params) {
    const url = params.id ? 'tms-archives-oil/updateOil' : 'tms-archives-oil/insertOil';
    return request(
        `/server/api/tms/${url}`,
        {
            method: 'POST',
            body: params,
        },
        true
    );
}
// 4、行车档案 -- 关联的加油--列表(未关联的)
export async function oilBindInfoList(params) {
    const { type, ...body } = params;
    return request(`/server/api/tms/tms-archives-oil/selectListNoLink`, {
        method: 'POST',
        body,
    });
}
// 5、行车档案 -- 确认关联的加油列表
export async function oilBindInfoOperate(params) {
    return request(
        `/server/api/tms/tms-archives-oil/linkOil`,
        {
            method: 'POST',
            body: params,
        },
        true
    );
}
//6、行车档案 --  移除加油记录
export async function removeOilInfo(params) {
    return request(`/server/api/tms/tms-archives-oil/removeOil`, {
        method: 'POST',
        body: params,
    });
}

// 1、油卡号
export async function oilCardList(params) {
    return request(
        `/server/api/tms/tms-oil/selectOilCard`,
        {
            method: 'POST',
            body: params,
        },
        true
    );
}
// 2、 百公里耗油
export async function calHundredConsump(params) {
    return request(`/server/api/tms/tms-oil/calculateHundredConsump`, {
        method: 'POST',
        body: params,
    });
}

// 四、压夜
// 1、压夜列表
export async function pressureInfoList(params) {
    const { type, ...body } = params;
    return request(`/server/api/tms/tms-archives/selectPressureNightList`, {
        method: 'POST',
        body,
    });
}
// 获取发车里程
export async function getStartMileage(params) {
    const { type, ...body } = params;
    return request(`/server/api/tms/tms-archives-trains/getStartMileage`, {
        method: 'POST',
        body,
    });
}
// 获取ETC发车金额
export async function getEtcStartAmount(params) {
    const { type, ...body } = params;
    return request(`/server/api/tms/tms-archives/getEtcStartAmount`, {
        method: 'POST',
        body,
    });
}

export async function selectDriverAdd(params) {
    return request(`/server/api/tms/tms-archives/driverBillDetail`, {
        method: 'POST',
        body: params,
    });
}

//
export async function getTrainNosToSZ(params) {
    return request(`/server/api/tms/tms-archives/getTrainNosToSZ`, {
        method: 'POST',
        body: params,
    });
}

//五、杂费
//根据费用类型获取费用科目 POST /tms-miscellaneous/getCostAccount
export async function getCostAccount(params) {
    return request(`/server/api/tms/tms-miscellaneous/getCostAccount`, {
        method: 'POST',
        body: params,
    });
}

// 二车队+一车队 刷新油耗：POST /tms-archives-oil/refreshOil
export async function refreshOil(params) {
    return request(`/server/api/tms/tms-archives-oil/refreshOil`, {
        method: 'POST',
        body: params,
    });
}

//二车队的普通按钮状态
export async function abledStatus(params){
    let url=''
    const {type,...param}=params
    console.log('params',params)
    switch(type){
        case 'back':
            url='tms-archives/BatchUpdateArchives'
            break;
    }
    return request(`/server/api/tms/${url}`, {
        method: 'POST',
        body: param,
    });
}